package com.hiwan.unions.view;

import android.content.Context;
import android.content.res.TypedArray;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.hiwan.unions.R;
import com.hiwan.unions.activity.loginRegister.LoginUserActivity;
import com.hiwan.unions.util.interfaces.NavigationLiterface;

/**
 * Created by llg on 2017/7/6.
 */
public class NavigationView extends RelativeLayout {
    private TextView goBackBtn, goBackBtn2;
    private TextView navigationTitleTxt;
    private TextView operationBtn;
    private RelativeLayout layout_title;
    private NavigationLiterface navigationLiterface;

    public NavigationView(Context context, AttributeSet attrs) {
        super(context, attrs);
        // TODO Auto-generated constructor stub
        LayoutInflater.from(context).inflate(R.layout.navigation_view, this);

        TypedArray a = context.obtainStyledAttributes(attrs,
                R.styleable.NavigationView);
        try {
            layout_title = (RelativeLayout) findViewById(R.id.layout_title);
            goBackBtn = (TextView) findViewById(R.id.goBackBtn);
            goBackBtn.setOnClickListener(listener);
            goBackBtn2 = (TextView) findViewById(R.id.goBackBtn2);
            goBackBtn2.setOnClickListener(listener);
            navigationTitleTxt = (TextView) findViewById(R.id.navigationTitleTxt);
            navigationTitleTxt.setText(a.getString(R.styleable.NavigationView_navigationTitle));
            operationBtn = (TextView) findViewById(R.id.operationBtn);
            operationBtn.setOnClickListener(listener);
        } catch (Exception e) {
            // TODO: handle exception
            e.printStackTrace();
        } finally {
            a.recycle();
        }
    }

    public void SetNavigationLiterface(NavigationLiterface listener) {
        this.navigationLiterface = listener;
    }

    private OnClickListener listener = new OnClickListener() {
        @Override
        public void onClick(View v) {
            switch (v.getId()) {
                case R.id.goBackBtn:
                    navigationLiterface.getGoBackBtn();
                    break;
                case R.id.goBackBtn2:
                    navigationLiterface.getGoBackBtn();
                    break;
                case R.id.operationBtn:
                    navigationLiterface.getOperationBtn();
                    break;
            }
        }
    };

    public TextView getNavigationTitleTxt() {
        return navigationTitleTxt;
    }

    public TextView getGoBackBtn() {
        return goBackBtn;
    }

    public TextView getGoBackBtn2() {
        return goBackBtn2;
    }

    public TextView getOperationBtn() {
        return operationBtn;
    }

    public RelativeLayout getTitle() {
        return layout_title;
    }


}
